package com.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.util.VerificationImageUtils;

@Controller
public class KaptchaController {
	@RequestMapping(value = "/kaptcha", method = RequestMethod.GET)
	public void ImageCaptcha(HttpServletRequest request,HttpServletResponse response,Model model, HttpSession session){
		response.setHeader("Cache-Control", "no-store");
		response.setHeader("Pragma", "no-cache");
		response.setDateHeader("Expires", 0);
		response.setContentType("image/jpeg");
		String verifyCode = VerificationImageUtils.generateVerifyCode(4);
		//����Ựsession
		session.setAttribute("codeimg", verifyCode.toLowerCase());
		int w = 200, h = 80;
		try {
			VerificationImageUtils.outputImage(w, h, response.getOutputStream(), verifyCode);
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
